import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  list = "/infra-service/genTable/pageGenTable",
  deleteGenTable = "/infra-service/genTable/deleteGenTable",
  importDbTable = "/infra-service/genTable/importDbTable",
  importDocumentTable = "/infra-service/genTable/importDocumentTable",
  genCode = "/infra-service/genCode",
  getGenTable = "/infra-service/genTable/getGenTable",
  updateGenTable = "/infra-service/genTable/update",
  syncDbTable = "/infra-service/genTable/syncDbTable",
  getGenInfo = "/infra-service/genTable/getGenInfo",
  listGenTableColumn = "/infra-service/genTable/listGenTableColumn",
  listGenTableIndex = "/infra-service/genTable/listGenTableIndex",
  saveOrUpdateGenTableInfo = "/infra-service/genTable/saveOrUpdateGenTableInfo",
  batchDeleteGenTableIndex = "/infra-service/genTable/batchDeleteGenTableIndex",
  batchDeleteGenTableColumn = "/infra-service/genTable/batchDeleteGenTableColumn",
  batchDeleteGenTable = "/infra-service/genTable/batchDeleteGenTable",
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params })

export const syncDbTable = (params) => defHttp.post({ url: `${Api.syncDbTable}`, params }, { joinParamsToUrl: true })
export const importDbTable = (params) => defHttp.post({ url: `${Api.importDbTable}`, params })
export const importDocumentTable = (params) => defHttp.post({ url: `${Api.importDocumentTable}`, params })
export const genCode = (params) => defHttp.post({ url: `${Api.genCode}`, params })
export const updateGenTable = (params) => defHttp.post({ url: `${Api.updateGenTable}`, params })

/**
 * 获取相关信息
 * @param params 表id
 * @returns
 */
export const getGenTable = (params) => defHttp.get({ url: `${Api.getGenTable}?tableId=${params}` })
export const getGenInfo = (params) => defHttp.get({ url: `${Api.getGenInfo}?tableId=${params}` })
export const listGenTableColumn = (params) => defHttp.get({ url: `${Api.listGenTableColumn}?tableId=${params}` }, { isTransformResponse: true })
export const listGenTableIndex = (params) => defHttp.get({ url: `${Api.listGenTableIndex}?tableId=${params}` })

export const saveOrUpdateGenTableInfo = (params) => defHttp.post({ url: `${Api.saveOrUpdateGenTableInfo}`, data: params })
export const batchDeleteGenTableIndex = (params) => defHttp.delete({ url: `${Api.batchDeleteGenTableIndex}?ids=${params}` })
export const batchDeleteGenTableColumn = (params) => defHttp.delete({ url: `${Api.batchDeleteGenTableColumn}?ids=${params}` })

/**
 * 批量删除gen_table
 * @param params
 */
export const batchDeleteGenTable = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteGenTable, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const deleteGenTable = (params) => defHttp.delete({ url: `${Api.deleteGenTable}?id=${params.id}` })
